<?php

namespace app\payment\admin;

use app\admin\controller\Admin;
use app\user\model\User as UserModel;
use think\facade\Env;
use think\Db;

/**
 * 支付首页控制器
 */
class Index extends Admin
{

    protected function initialize()
    {
        parent::initialize();

        $info = UserModel::where(['id' => session('user_auth.uid')])->find();
        // 给支付做下权限判断
        $this->merchant_id = $info['merchant_id'] ? $info['merchant_id'] : 12345678;
        $this->role = $info['role'] ? $info['role'] : 100;
        $this->have_auth = 1;
        $this->auth_role = 12;
        $this->no_auth = $this->role > $this->auth_role ? true : false;
        $this->uid = $info['id'] ? $info['id'] : 12345678;

        $this->merchant_info = Db::name('payment_merchant_config')->where(['id' => $this->merchant_id])->find();
        $this->manage_merchant = $this->merchant_info['manage_merchant'] ? json_decode($this->merchant_info['manage_merchant'], true) : '';

        $this->is_agent = false;
        if ($this->merchant_info['agent_status'] == 1 && in_array($this->role, ['13', '14', '15'])) {
            $this->is_agent = true;
        }

        // 文件夹路径(下载)
        $this->file_path = Env::get('root_path') . 'data' . DIRECTORY_SEPARATOR . 'download' . DIRECTORY_SEPARATOR;

        // 安全配置

        // 增加
        $this->add_safe = 0;
        // 编辑
        $this->edit_safe = 0;
        // 查看
        $this->see_safe = 0;
        // 删除
        $this->delete_safe = 0;
        // 模拟支付通知
        $this->simulation_pay_notify_safe = 0;
        // 模拟代付通知
        $this->simulation_paid_notify_safe = 0;
        // 模拟退款通知
        $this->simulation_refund_notify_safe = 0;
        // 手动代付
        $this->manual_paid_safe = 0;
        // 手动退款
        $this->manual_refund_safe = 1;
        // 手动批量退款
        $this->manual_batch_refund_safe = 1;
        // 验证码权限
        $this->verificationcode_auth = 0;
        // 密钥查看
        $this->key_see_safe = 0;
        // 系统安全密码
        $this->system_safe_pwd = '';

        // 其它
        $log_see = 1;
        $controller = request()->controller();
        $action = request()->action();
        if ($controller == 'Order' && $action == 'index') {
            $log_see = 0;
            if ($this->role == 7 || $this->role == 11) {
                payment_error_log('3' . $this->merchant_id, $this->merchant_id, input());
            }
        }
        if ($controller == 'AlipayPaid' && $action == 'index') {
            $log_see = 0;
            if ($this->role == 7 || $this->role == 11) {
                payment_error_log('6' . $this->merchant_id, $this->merchant_id, input());
            }
        }
        if ($controller == 'Report' && $action == 'company_analyse') {
            $log_see = 0;
            if ($this->role == 7 || $this->role == 11) {
                payment_error_log('7' . $this->merchant_id, $this->merchant_id, input());
            }
        }
        if ($controller == 'Report' && $action == 'paid') {
            $log_see = 0;
            if ($this->role == 7 || $this->role == 11) {
                payment_error_log('9' . $this->merchant_id, $this->merchant_id, input());
            }
        }
        if ($controller == 'PaidCompany' && $action == 'index') {
            $log_see = 0;
        }
        if ($controller == 'Redis' && $action == 'sql') {
            $log_see = 0;
        }
        if ($controller == 'Test') {
            $log_see = 0;
        }

        if ($log_see) {
            if ($this->role == 7 || $this->role == 11) {
                payment_error_log($this->merchant_id, $this->merchant_id, input());
            }
        }
    }

    /**
     * 首页
     * @return mixed
     */
    public function index()
    {
        $this->redirect('payment/order/index');
    }
}
